/**
 * ReduceTestJava.java
 *
 * @author: ZhuJiahui
 * @date: 2019/3/10 20:53
 */
package six;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function2;

import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: ZhuJiahui
 * @version: 1.0
 */
public class ReduceTestJava {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("ReduceTest");
        JavaSparkContext sc = new JavaSparkContext(conf);

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
        JavaRDD<Integer> listRDD = sc.parallelize(list);

//        Integer result = listRDD.reduce(
//                new Function2<Integer, Integer, Integer>() {
//                    @Override
//                    public Integer call(Integer v1, Integer v2)
//                            throws Exception {
//                        return v1 + v2;
//                    }
//                });
        Integer result = listRDD.reduce((x, y) -> x + y);
        System.out.println(result);
    }
}
